<?php

	if (!isset($_SESSION)) {
		session_start();
	}

	if (array_key_exists('userid', $_SESSION) && array_key_exists('username', $_SESSION)){
			$smarty->assign('usuari', $_SESSION['username']);
	} else if (array_key_exists('userId', $_COOKIE) && array_key_exists('userIdCrypt', $_COOKIE) &&
		array_key_exists('userName', $_COOKIE)){
		$username = htmlentities($_COOKIE['userName']);
		if (sha1(Mp3_Constants::SALT.$_COOKIE['userId']) == $_COOKIE['userIdCrypt']){
			$smarty->assign('usuari', $username);
		}
	}else{
		$smarty->assign('usuari', '');
	}